<template>
  <el-dialog v-model="dialogTableVisible4" :show-close="true" width="60%">
    <div style="height: 465px; overflow: hidden">
      <div style="position: absolute; top: 5px">
        <el-input
          style="width: 30%; margin-left: 2px"
          v-model="inputK3Bm"
          placeholder="k3编码"
        >
          <template #prefix>
            <el-icon class=""><search /></el-icon>
          </template>
        </el-input>
        <el-input
          style="width: 30%; margin-left: 2px"
          v-model="inputK3Mc"
          placeholder="k3名称"
        >
          <template #prefix>
            <el-icon class=""><search /></el-icon>
          </template>
        </el-input>
        <el-button style="margin-left: 5px" @click="searc3Kh" type="primary"
          >查询</el-button
        >
        <el-button style="margin-left: 5px" @click="put3Kh" type="primary"
          >添加</el-button
        >
        <el-button style="margin-left: 5px" @click="updateK3" type="success"
          >更新k3</el-button
        >
      </div>
      <div class="dialogDiv">
        <el-table
          border
          stripe
          :data="tableData3"
          @row-click="RowClick3"
          :cell-style="cellStyle"
          :header-cell-style="headerCellStyle"
          max-height="420px"
          height="420px"
          @selection-change="handleSelectionChange1"
          show-overflow-tooltip
        >
          <el-table-column type="selection" width="65" align="center" />
          <el-table-column prop="k3bm" label="Id" width="80" align="center" />
          <el-table-column prop="fnumber" label="k3编码" width="120" align="center" />
          <el-table-column prop="bmmc" label="k3名称" width="150" align="center" />
          <el-table-column prop="wlgg" label="物料规格" width="150" align="center" />
          <el-table-column prop="jldw" label="计量单位" width="60" align="center" />
        </el-table>

        <div class="demo-pagination-block">
          <el-pagination
            v-model:current-page="page2"
            v-model:page-size="limit2"
            :page-sizes="[100, 200, 300, 400]"
            :small="small"
            :disabled="disabled"
            :background="background"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total3"
            @size-change="handleSizeChange3"
            @current-change="handleCurrentChange3"
          />
        </div>
      </div>
    </div>
  </el-dialog>
  <el-dialog
    v-model="dialogTableVisible2"
    :show-close="true"
    width="60%"
    style="z-index: 100"
  >
    <div style="height: 500px; overflow: hidden">
      <!-- <div style="top: 5px">
        <el-input style="width: 150px; margin-left: 2px" v-model="ID" placeholder="id">
          <template #prefix>
            <el-icon class=""><search /></el-icon>
          </template>
        </el-input>
        <el-input
          style="width: 150px; margin-left: 2px"
          v-model="tableName"
          placeholder="表名"
        >
          <template #prefix>
            <el-icon class=""><search /></el-icon>
          </template>
        </el-input>

        <el-button style="margin-left: 5px" @click="geSysStatus" type="primary"
          >查询</el-button
        >
      </div> -->
      <div class="dialogDiv">
        <el-table
          border
          stripe
          :data="tableData2"
          @row-click="RowClick2"
          :cell-style="cellStyle"
          :header-cell-style="headerCellStyle"
          max-height="450px"
          height="450px"
          @selection-change="handleSelectionChange2"
          show-overflow-tooltip
        >
          <el-table-column fixed type="index" width="60" align="center" />
          <el-table-column fixed type="selection" width="50" align="center" />
          <!-- <el-table-column
            prop="equipmentId"
            label="设备编号"
            width="100"
            align="center"
          />
          <el-table-column
            prop="equipmentName"
            label="设备名称"
            width="100"
            align="center"
          /> -->
          <el-table-column
            prop="mechanicalStructureId"
            label="结构编号"
            width="100"
            align="center"
          />
          <el-table-column
            prop="structureName"
            label="结构名称"
            width="100"
            align="center"
          />
          <el-table-column prop="ecs_name" label="零件名称" width="100" align="center" />
          <el-table-column
            prop="structureID"
            label="位置编号"
            width="100"
            align="center"
          />
          <el-table-column prop="model" label="型号" width="100" align="center" />
          <el-table-column
            prop="workingFaceOuterDiameterStandard"
            label="工作面外径标准"
            width="120"
            align="center"
          />
          <el-table-column
            prop="minWorkingFaceOuterDiameter"
            label="最小工作面外径"
            width="120"
            align="center"
          />
          <el-table-column
            prop="maxWorkingFaceOuterDiameter"
            label="最大工作面外径"
            width="120"
            align="center"
          />
          <el-table-column
            prop="category_name"
            label="类别名称"
            width="100"
            align="center"
          />
          <el-table-column prop="quantity" label="数量" width="100" align="center" />
          <el-table-column prop="direction" label="说明" align="center" />
        </el-table>
        <div class="demo-pagination-block">
          <el-pagination
            v-model:current-page="page2"
            v-model:page-size="limit2"
            :page-sizes="[100, 200, 300, 400]"
            :small="small"
            :disabled="disabled"
            :background="background"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total2"
            @size-change="handleSizeChange2"
            @current-change="handleCurrentChange2"
          />
        </div>
      </div>
    </div>
  </el-dialog>
  <div
    v-if="dialogTableVisible1"
    :fullscreen="false"
    :modal="false"
    :show-close="false"
    :width="screenWidth + 20 + 'px'"
    :append-to-body="true"
    style="
      position: absolute;
      left: 6rem;
      margin-top: 42px;
      z-index: 10;
      background-color: white;
    "
    :close-on-click-modal="false"
  >
    <div :style="{ width: screenWidth - 96 + 'px' }">
      <div
        :style="{
          height: '40px',
          borderBottom: '1px solid #ccc',
          width: '100%',
        }"
      >
        <div style="position: absolute; right: 15px">
          <el-button @click="flushed" type="primary"> 刷新</el-button>
          <!-- <el-button v-if="Permission" @click="upButton" type="primary">
        修改业务员</el-button
      > -->
          <!-- <el-button @click="addRow" type="primary">增行</el-button>
          <el-button @click="deleteSelectedRows" type="danger">删除</el-button> -->
          <el-button
            type="primary"
            @click="insertMaterialsFixed()"
            v-if="showInsertButton"
            >保存</el-button
          >
          <el-button
            :disabled="isDis"
            type="primary"
            @click="updateMaterialsFixed()"
            v-if="!showInsertButton"
            >保存</el-button
          >

          <el-button @click="OFFdialogTableVisible" type="danger">关闭</el-button>
        </div>
      </div>
    </div>
    <div
      ref="titleDiv"
      :style="{
        backgroundColor: 'rgba(247, 247, 247, 0.903)',
        height: childTableHeight - 89 + 'px',
        width: screenWidth - 109 + 'px',
      }"
    >
      <!-- 主表字段 -->
      <el-form ref="ruleFormRef" status-icon :rules="rules" :model="form" :inline="true">
        <el-row :gutter="0">
          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 120px; padding-right: 5px"
              ><span style="color: red">*</span>单件唯一码</label
            >
            <el-input style="width: 200px" v-model="form.unique_code" placeholder="" />
          </el-form-item>

          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 120px; padding-right: 5px"
              ><span style="color: red">*</span>供应商唯一码</label
            >
            <el-input
              style="width: 200px"
              v-model="form.supplier_unique_code"
              placeholder=""
              clearable
            />
          </el-form-item>
          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 120px; padding-right: 5px">快速检索码</label>
            <el-input
              style="width: 200px"
              v-model="form.qr_code"
              placeholder=""
              clearable
            />
          </el-form-item>
          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 120px; padding-right: 5px">登记日期 </label>
            <el-input
              style="width: 200px"
              :readonly="true"
              v-model="form.f_date"
              disabled
              placeholder="系统自动生成"
            />
          </el-form-item>
        </el-row>
        <el-row :gutter="0">
          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 120px; padding-right: 5px">登记类型</label>
            <el-select
              style="width: 200px"
              clearable
              v-model="form.bus_type"
              :readonly="true"
              @change="inputTypeChange()"
            >
              <el-option label="期初登记" value="0"></el-option>
              <el-option label="领料登记" value="1"></el-option>
              <el-option label="启用登记" value="2"></el-option>
              <el-option label="维修登记" value="3"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 120px; padding-right: 5px">物料状态</label>
            <el-select
              style="width: 200px"
              clearable
              v-model="form.material_state"
              :readonly="true"
              :disabled="inputTypeTrue"
            >
              <el-option label="初始状态" value="0"></el-option>
              <el-option label="在用状态" value="1"></el-option>
              <el-option label="搁置状态" value="2"></el-option>
              <el-option label="报废状态" value="3"></el-option>
              <el-option label="注销" value="4"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 120px; padding-right: 5px">流转状态</label>
            <el-select
              style="width: 200px"
              clearable
              v-model="form.circulation_state"
              :readonly="true"
              :disabled="inputTypeTrue"
            >
              <el-option label="初始登记" value="0"></el-option>
              <el-option label="领回/送回" value="1"></el-option>
              <el-option label="安装" value="3"></el-option>
              <el-option label="拆卸" value="5"></el-option>
              <el-option label="送磨" value="6"></el-option>
              <el-option label="磨削" value="8"></el-option>
              <el-option label="维修" value="9"></el-option>
              <el-option label="搁置" value="11"></el-option>
              <el-option label="报废" value="12"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 120px; padding-right: 5px">锁定</label>
            <el-select
              style="width: 200px"
              clearable
              v-model="form.lock"
              :readonly="true"
              disabled
            >
              <el-option label="未锁定" value="0"></el-option>
              <el-option label="锁定" value="1"></el-option>
            </el-select>
          </el-form-item>
        </el-row>
        <el-row :gutter="0">
          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 120px; padding-right: 5px"
              ><span style="color: red">*</span>型号</label
            >
            <el-input
              style="width: 200px"
              v-model="form.model_name"
              :readonly="true"
              placeholder="请选择"
              @click="openBusiness(index)"
            />
          </el-form-item>
          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 120px; padding-right: 5px"
              ><span style="color: red">*</span>零件名称</label
            >
            <el-input
              style="width: 200px"
              v-model="form.ecs_name"
              :readonly="true"
              disabled
            />
          </el-form-item>
          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 120px; padding-right: 5px"
              ><span style="color: red">*</span>类别名称</label
            >
            <el-input
              style="width: 200px"
              v-model="form.category_name"
              :readonly="true"
              disabled
            />
          </el-form-item>
          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 120px; padding-right: 5px"
              ><span style="color: red">*</span>结构名称</label
            >
            <el-input
              style="width: 200px"
              v-model="form.structureName"
              :readonly="true"
              disabled
            />
          </el-form-item>
        </el-row>
        <el-row :gutter="0">
          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 120px; padding-right: 5px"
              ><span style="color: red">*</span>初始外径</label
            >

            <el-input
              placeholder="必输"
              style="width: 200px"
              v-model="form.init_outside_diameter"
              @blur="InitDiameterBlur('init_outside_diameter', index)"
            />
          </el-form-item>
          <!-- <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 120px; padding-right: 5px">剩余磨削量</label>
            <el-input
              style="width: 200px"
              v-model="form.residualGrindingCapacity"
              placeholder=""
              clearable
              @blur="() => handleBlur('residualGrindingCapacity', index)"
              disabled
            />
          </el-form-item> -->
          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 120px; padding-right: 5px"
              >累计磨削次数</label
            >
            <el-input
              style="width: 200px"
              v-model="form.c_g_num"
              placeholder=""
              clearable
              @blur="() => handleBlur('c_g_num', index)"
            />
          </el-form-item>

          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 120px; padding-right: 5px"
              >累计磨削数量</label
            >
            <el-input
              style="width: 200px"
              v-model="form.c_g_quantity"
              placeholder=""
              clearable
              @blur="() => handleBlur('c_g_quantity', index)"
              :disabled="!gunXiang || !daoZhou"
            />
          </el-form-item>
        </el-row>

        <el-row :gutter="0">
          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 120px; padding-right: 5px"
              ><span style="color: red">*</span>默认标准</label
            >
            <el-input
              style="width: 200px"
              v-model="form.processName"
              :readonly="true"
              placeholder="请选择"
              @click="openEqipmentParts()"
            />
          </el-form-item>
          <!-- <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 120px; padding-right: 5px">颜色</label>
            <el-input
              style="width: 200px"
              v-model="form.color"
              :readonly="true"
              placeholder=""
              disabled
            />
          </el-form-item> -->

          <!-- <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 120px; padding-right: 5px">零件编号</label>
            <el-input
              style="width: 200px"
              :readonly="true"
              v-model="form.businessProjectId"
              placeholder=""
              disabled
            />
          </el-form-item> -->
          <!-- <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 120px; padding-right: 5px">磨削总量</label>
            <el-input
              style="width: 200px"
              v-model="form.grindingTotal"
              placeholder=""
              :readonly="true"
              disabled
            />
          </el-form-item> -->
          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 120px; padding-right: 5px">最小外径</label>
            <el-input
              style="width: 200px"
              v-model="form.minWorkingFaceOuterDiameter"
              placeholder=""
              :readonly="true"
              disabled
            />
          </el-form-item>
        </el-row>
      </el-form>
    </div>
  </div>
  <el-container>
    <el-header height="65px" :style="{ 'border-bottom': '1px solid #ccc' }">
      <!-- 头部按钮 -->
      <el-row type="flex" justify="end" style="background-color: rgb(211, 227, 253)">
        <div>
          <el-button @click="searchButton" type="primary"> 查询</el-button>
          <el-button @click="() => openRatify('2', '5', '请确认签批')" type="success">
            签批</el-button
          >
          <el-button @click="() => openRatify('2', '6', '请确认弃签')" type="success">
            弃签</el-button
          >
          <el-button @click="() => openRatify('1', '3', '请确认审核')" type="warning">
            审核</el-button
          >
          <el-button @click="() => openRatify('1', '4', '请确认弃审')" type="warning">
            弃审</el-button
          >
          <el-button @click="() => openRatify('1', '9', '请确认删除')" type="danger">
            删除</el-button
          >
          <!-- <el-button @click="handleAudit" type="warning"> 审核</el-button> -->
          <!-- <el-button @click="handleAudit0" type="warning"> 弃审</el-button> -->
          <el-button @click="openInseart" type="success"> 新增</el-button>
          <el-button @click="deleteButton" type="danger"> 删除</el-button>
        </div>
        <!-- <div class="title">需求汇总统计表</div> -->
      </el-row>
      <div
        style="
          margin-left: 6rem;
          height: 30px;

          background: rgb(241, 244, 243);
          margin-bottom: 0;
          position: relative;
          display: flex;
          justify-content: flex-start;
        "
      >
        <el-input
          style="width: 10%; height: 25px; margin-left: 2px; margin-top: 2px"
          v-model="uniqueCode"
          placeholder="单件编号"
        >
          <template #prefix>
            <el-icon class="">
              <search />
            </el-icon>
          </template>
        </el-input>
        <el-input
          style="width: 10%; height: 25px; margin-left: 2px; margin-top: 2px"
          v-model="modelName"
          placeholder="型号"
        >
          <template #prefix>
            <el-icon class="">
              <search />
            </el-icon>
          </template>
        </el-input>

        <el-input
          style="width: 10%; height: 25px; margin-left: 2px; margin-top: 2px"
          v-model="ecsName"
          placeholder="零件名称"
        >
          <template #prefix>
            <el-icon class="">
              <search />
            </el-icon>
          </template>
        </el-input>
        <el-input
          style="width: 10%; height: 25px; margin-left: 2px; margin-top: 2px"
          v-model="structureName"
          placeholder="结构名称"
        >
          <template #prefix>
            <el-icon class="">
              <search />
            </el-icon>
          </template>
        </el-input>
        <el-input
          style="width: 10%; height: 25px; margin-left: 2px; margin-top: 2px"
          v-model="unique_code"
          placeholder="单件编号精准查询"
        >
          <template #prefix>
            <el-icon class="">
              <search />
            </el-icon>
          </template>
        </el-input>
        <el-select
          style="width: 10%; height: 25px; margin-left: 2px; margin-top: 2px"
          v-model="f_type"
          placeholder="登记类型"
          clearable
          size="small"
        >
          <el-option label="期初登记" value="0"></el-option>
          <el-option label="领料登记" value="1"></el-option>
          <el-option label="启用登记" value="2"></el-option>
          <el-option label="维修登记" value="3"></el-option>
        </el-select>
      </div>
    </el-header>
    <el-container>
      <el-container>
        <el-main style="padding: 2px 2px 0 2px; margin-left: 6rem">
          <el-table
            v-loading="loading"
            ref="table"
            :data="tableData"
            border
            stripe
            :cell-style="cellStyle"
            :header-cell-style="headerCellStyle"
            @selection-change="handleSelectionChange"
            @row-dblclick="handleRowClick"
            @row-click="RowClick"
            :row-style="rowState"
            :row-key="(row: any) => row.id"
            :max-height="screenHeight"
            :height="screenHeight"
            :max-width="'300px'"
          >
            <el-table-column fixed type="index" width="60" align="center" />
            <el-table-column fixed type="selection" width="50" align="center" />
            <el-table-column
              prop="unique_code"
              label="单件编号"
              width="100"
              align="center"
            />

            <el-table-column
              prop="structureCode"
              label="结构编号"
              width="100"
              align="center"
            />
            <el-table-column
              prop="structureName"
              label="结构名称"
              width="100"
              align="center"
            />

            <el-table-column
              prop="ecs_name"
              label="零件名称"
              width="100"
              align="center"
            />
            <el-table-column
              prop="material_state_name"
              label="物料状态"
              width="100"
              align="center"
            />
            <el-table-column
              prop="circulation_state_name"
              label="流转状态"
              width="100"
              align="center"
            />
            <el-table-column
              prop="lock_name"
              label="锁定状态"
              width="100"
              align="center"
            />
            <el-table-column prop="model_name" label="型号" width="80" align="center" />
            <el-table-column
              prop="specification"
              label="规格"
              width="80"
              align="center"
            />
            <el-table-column
              prop="category_name"
              label="零件类别"
              width="100"
              align="center"
            />

            <el-table-column
              prop="ratify_state_name"
              label="签批状态"
              width="100"
              align="center"
            />
            <el-table-column
              prop="state_name"
              label="审核状态"
              width="100"
              align="center"
            />
          </el-table>
        </el-main>
        <el-footer style="height: 20px">
          <div class="demo-pagination-block">
            <el-pagination
              v-model:current-page="page"
              v-model:page-size="limit"
              :page-sizes="[50, 500, 1000, 1500, 2000, 8000]"
              :small="true"
              :background="true"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
            />
          </div>
        </el-footer>
      </el-container>
    </el-container>
  </el-container>
  <SearchTableDialog
    ref="sed"
    @row-data="handleRowData"
    @row-datas="handleRowDatas"
  ></SearchTableDialog>
</template>
<script setup lang="ts">
import {
  ref,
  watch,
  reactive,
  onMounted,
  onBeforeMount,
  computed,
  nextTick,
  onUnmounted,
  toRefs,
} from "vue";
import { Delete, Edit, Search, Share, Upload, Calendar } from "@element-plus/icons-vue";
import {
  ElButton,
  ElDialog,
  dialogEmits,
  ElMessage,
  ElTable,
  TableColumnCtx,
  ElMessageBox,
} from "element-plus";
import type { FormInstance, FormRules } from "element-plus";

import { CircleCloseFilled } from "@element-plus/icons-vue";
import { useRouter } from "vue-router";
import axios from "../../../axios/axiosInstance.ts";
import Cookies from "js-cookie";
import { format } from "date-fns";
import zhCn from "element-plus/dist/locale/zh-cn.mjs";
// crud封装组件
import * as crud from "../../../components/utils/crud.ts";
import * as newCrud from "../../../components/utils/newCrud.ts";

import SearchTableDialog from "@/components/dialogs/SearchTableDialog.vue";
import * as notifications from "../../../components/utils/notification.ts";
// 时间
// 获取当前时间
import moment from "moment";

const page1 = ref(1);
const page2 = ref(1);
const page3 = ref(1);
const page4 = ref(1);
const page5 = ref(1);

const dialogTableVisible2 = ref(false);
const dialogTableVisible3 = ref(false);
const dialogTableVisible4 = ref(false);
const dialogTableVisible5 = ref(false);
const limit1 = ref(50);
const limit2 = ref(50);
const limit3 = ref(50);
const limit4 = ref(50);
const limit5 = ref(50);
const total1 = ref(10);
const total2 = ref(10);
const total3 = ref(10);
const total4 = ref(10);
const total5 = ref(10);
const categoryOfConsumables = ref("");
const djStatus = ref(0);
const direction = ref("");
const wlbm = ref("");
const ID = ref("");

const getCurrentFormattedDateTime = () => {
  const currentDateTime = new Date();

  // 格式化当前时间
  const formattedDateTime = currentDateTime.toLocaleString("zh-CN", {
    year: "numeric",
    month: "2-digit",
    day: "2-digit",
    hour: "2-digit",
    minute: "2-digit",
    second: "2-digit",
  });
  // const formattedDateTime = format(currentDateTime, "YYYY-MM-dd HH:mm:ss");

  return formattedDateTime;
};
// 获取年月日
const getCurrentFormattedDate = () => {
  const currentDateTime = new Date();

  // 格式化当前时间，只获取年月日
  const formattedDate = currentDateTime.toLocaleString("zh-CN", {
    year: "numeric",
    month: "2-digit",
    day: "2-digit",
  });

  return formattedDate;
};
// 权限控制
const searchButtonPermissionsA = ref(false);
const menuId = ref(0);
const buttonVariables = {
  searchButtonPermissionsA,
};
const selectPermissionsButton = () => {
  const userName = Cookies.get("userName");
  axios({
    url: "/select/Permissions/Button",
    method: "post",
    data: {
      userName: userName,
      menuId: menuId.value,
    },
  }).then((res) => {
    res.data.forEach((button) => {
      const buttonName = button.buttonName;
      if (buttonVariables.hasOwnProperty(buttonName)) {
        buttonVariables[buttonName].value = true;
      }
    });
  });
};
selectPermissionsButton();
//权限结束
const tableData = ref([]);
const dialogTableVisible1 = ref(false);
const loading = ref(false);
const page = ref(1);
const limit = ref(50);
const total = ref(50);
const id = ref("");
const uniqueCode = ref("");
const modelName = ref("");
const ecsName = ref("");
const structureName = ref("");
const unique_code = ref("");
const f_type = ref("");
const selectBusinessDate = computed(() => ({
  info: {
    id: id.value,
    uniqueCode: uniqueCode.value,
    modelName: modelName.value,
    ecsName: ecsName.value,
    structureName: structureName.value,
    unique_code: unique_code.value,
    bus_type: f_type.value,
  },
  pageInfo: {
    page: page.value,
    limit: limit.value,
  },
}));
const handleSizeChange = (val: number) => {
  getModel();
};
const handleCurrentChange = (val: number) => {
  getModel();
};
const searchButton = () => {
  getModel();
};
const getUserId = async () => {
  const userName = Cookies.get("userName");
  const res = await crud.fetchData("UserDe/getUserDe", "post", {
    input5: userName,
  });
  const timestamp = new Date().getTime();
  const fdateTime = moment(timestamp).format("YYYY-MM-DD HH:mm:ss");
  const fdate = moment(timestamp).format("YYYY-MM-DD");
  //登记日期
  form.f_date = fdate;
  //签批人
  form.ratify_person_id = res[0].userId;
  form.ratify_person_name = res[0].userName;
  form.ratify_datatime = fdateTime;
  //制单人
  form.create_person_id = res[0].userId;
  form.create_person_name = res[0].userName;
  form.create_datatime = fdateTime;
  //修改人
  form.modify_person_id = res[0].userId;
  form.modify_person_name = res[0].userName;
  form.modify_datetime = fdateTime;
  //审核人
  form.verify_person_id = res[0].userId;
  form.verify_person_name = res[0].userName;
  form.verify_datetime = fdateTime;
};
const getModel = async () => {
  loading.value = true;
  try {
    const res = await newCrud.fetchData(
      "/Part/singleList",
      "post",
      selectBusinessDate.value
    );
    if (res.info.length == 0) {
      total.value = 0;
      tableData.value = [];
      loading.value = false;
      return;
    }
    console.log(res);
    loading.value = false;
    total.value = res.info[0].total;
    tableData.value = res.info;
    //  const definitionsList = res.info;

    //  total.value = definitionsList[0].total;
    //  loading.value = false;
    //  tableData.value = definitionsList.map((item: any) => ({
    //    ...item,
    //    state: item.state == 0 ? "待审核" : "已审核",
    //  }));
  } catch (error) {
    loading.value = false;
    console.error("请求失败:", error);
  }
};
getModel();
// 表格
const headerCellStyle = {
  // E9E9E7
  borderColor: "#B9C9C7",
  backgroundColor: "#F2F4FA", // 表头背景颜色
  fontWeight: "bold", // 表头文字粗细
  color: "#1F2129",
  // padding: "0 0 0 30px",
};
const rowState = (arg) => {
  return {
    height: "20px", // 设置合适的行高值
    fontSize: "12px", // 设置合适的字体大小值
    // color: "black",
  };
};

const handleBlur = (fieldName, rowIndex) => {
  const val = form[fieldName];
  if (fieldName == "c_g_quantity") {
    if (!isNaN(parseFloat(val)) && isFinite(val)) {
      // 将数字保留四位小数
      //  form[prop] = parseFloat(val).toFixed(4);
      const roundedVal = parseFloat(val)
        .toString()
        .match(/^-?\d+(\d{0,0})?/)[0];
      form.c_g_quantity = roundedVal;
      return;
    } else {
      // 如果不是有效数字，清空表单
      form.c_g_quantity = "";
      return;
    }
  }

  validateAndFormat(fieldName, val);
};
const validateAndFormat = (prop, val) => {
  if (!isNaN(parseFloat(val)) && isFinite(val)) {
    // 将数字保留四位小数
    //  form[prop] = parseFloat(val).toFixed(4);
    const roundedVal = parseFloat(val)
      .toString()
      .match(/^-?\d+(\.\d{0,4})?/)[0];
    form[prop] = roundedVal;
  } else {
    // 如果不是有效数字，清空表单
    form[prop] = "";
  }
};
const RowClick = (row, selection) => {
  table.value.toggleRowSelection(row);
};
const selectedRows = ref([]);
const table = ref();

const cellStyle = ({ row, column, rowIndex, columnIndex }) => {
  if (selectedRows.value.find((selectedRow) => selectedRow.id === row.id)) {
    return {
      backgroundColor: "#DFF0DB !important",
      borderColor: "#B9C9C7",
      padding: "4px",
    };
  } else {
    return { borderColor: "#B9C9C7", padding: "4px", margin: 0 };
  }
};
const handleSelectionChange = (selection: any) => {
  selectedRows.value = selection;
};
const screenHeight = ref(null);
const screenWidth = ref(null);
const childTableHeight = ref(null);

const getScreenHeight = () => {
  childTableHeight.value = window.innerHeight;
  screenHeight.value = window.innerHeight - 146;
  screenWidth.value = window.innerWidth;
};
getScreenHeight();
const requestDataAsid = computed(() => ({
  deleteIdList: selectedRows.value,
}));

const openRatify = async (a, b, c) => {
  try {
    const result = await notifications.showConfirmDialog("", c, "success");

    if (!result) {
      return;
    }
    console.log("selectedRows.value.length:" + selectedRows.value.length);

    if (selectedRows.value.length == 0) {
      notifications.showMessage("请至少选择一行进行操作", "error");
      // notifications.showMessage("xxxxxx", "error");
      return;
    }

    //签批意见
    //  formMainTableData.value.ratifyDesc = formMainTable.value.ratifyDesc;

    var idList = selectedRows.value.map((row) => row.id).join(",");
    //  var requestData = await requestDataAsid.value;

    //  console.log("requestData:" + JSON.stringify(requestData));
    const res = await newCrud.sendRequest("/Part/stateUp", "post", {
      info: {
        idList: idList,
        bus_code: "53",
        field_oper_code: a,
        s_oper_code: b,
        //签批
        ratify_person_id: form.ratify_person_id,
        ratify_person_name: form.ratify_person_name,
        ratify_person_time: form.ratify_person_time,
        //审核
        verify_person_id: form.verify_person_id,
        verify_person_name: form.verify_person_name,
        verify_datetime: form.verify_datetime,
      },
    });
    if (res.code == 200 || res.code == 1) {
      getModel();
    }
  } catch (error) {
    console.error("请求失败:", error);
  }
};

const handleAudit = async () => {
  if (selectedRows.value.length === 0) {
    alert("请勾选需要审核的数据！");
    return;
  }

  if (confirm("确认审核吗？") == false) {
    return;
  }
  // .then(() => {

  const userName = Cookies.get("userName");
  const res = await crud.sendRequest("/Part/auditing", "post", {
    idList: selectedRows.value.map((row) => row.id),
    state: 1,
  });
  if (res.code == 200 || res.code == 1) {
    searchButton();
    return;
  }

  // .catch(() => {});
};
const handleAudit0 = async () => {
  if (selectedRows.value.length === 0) {
    alert("请勾选需要弃审的数据！");
    return;
  }
  if (confirm("确认弃审吗？") == false) {
    return;
  }
  const res = await crud.sendRequest("/Part/auditing", "post", {
    idList: selectedRows.value.map((row) => row.id),
    state: 0,
  });

  if (res.code == 200 || res.code == 1) {
    searchButton();
    return;
  }

  // .catch(() => {});
};
const deleteButton = async () => {
  if (selectedRows.value.length === 0) {
    alert("请勾选需要删除的数据！");
    return;

    // 在这里执行删除选中行的逻辑，可以使用 selectedRows.value[0] 获取唯一选中的一行
  }
  if (confirm("确认删除吗？") == false) {
    return;
  }
  const res = await crud.sendRequest("/Part/delete", "post", {
    idList: selectedRows.value.map((row) => row.id),
  });

  if (res.code == 200 || res.code == 1) {
    searchButton();
    return;
  }
};
const isDisabled = ref(true);
const gun = ref(true);
const dao = ref(true);
const getao = ref(true);
const gunXiang = ref(true);
const daoZhou = ref(true);
const clickOrganizationStatus = () => {
  form.categoryOfConsumables = categoryOfConsumables.value;
  if (form.categoryOfConsumables == 0) {
    gun.value = false;
    gunXiang.value = true;
    daoZhou.value = true;
    getao.value = true;
    dao.value = true;
    form.thicknessStandard = "";
    form.innerHoleStandard = "";
  }
  if (form.categoryOfConsumables == 1) {
    dao.value = false;
    gun.value = true;
    getao.value = true;
    gunXiang.value = true;
    daoZhou.value = true;
    form.width = "";
    form.height = "";
    form.taperStandard = "";
    form.taperLength = "";
    form.taperHeight = "";
  }
  if (form.categoryOfConsumables == 2) {
    getao.value = false;
    gun.value = true;
    dao.value = true;
    gunXiang.value = true;
    daoZhou.value = true;
    form.width = "";
    form.height = "";
    form.taperStandard = "";
    form.taperLength = "";
    form.taperHeight = "";
  }
  if (form.categoryOfConsumables == 3) {
    gunXiang.value = false;
    gun.value = true;
    getao.value = true;
    dao.value = true;
    daoZhou.value = true;
    form.diameter = "";
    form.workingFaceLength = "";
    form.workingFaceOuterDiameterStandard = "";
    form.nonWorkingFaceOuterDiameterStandard = "";
    form.innerHoleStandard = "";
    form.hardnessStandard = "";
    form.thicknessStandard = "";
    form.c_g_quantity = "";
    form.ljgrindingNumber = "";
    form.ljgrindingTimes = "";
    form.taperStandard = "";
    form.taperLength = "";
    form.taperHeight = "";
  }
  if (form.categoryOfConsumables == 4) {
    daoZhou.value = false;
    gun.value = true;
    getao.value = true;
    dao.value = true;
    gunXiang.value = true;
    form.width = "";
    form.height = "";
    form.workingFaceLength = "";
    form.innerHoleStandard = "";
    form.hardnessStandard = "";
    form.thicknessStandard = "";
    form.workingFaceOuterDiameterStandard = "";
    form.nonWorkingFaceOuterDiameterStandard = "";
    form.c_g_quantity = "";
    form.ljgrindingNumber = "";
    form.ljgrindingTimes = "";
    form.taperStandard = "";
    form.taperLength = "";
    form.taperHeight = "";
  }
};
const optionss = reactive([
  {
    value: "0",
    label: "辊轴类",
  },
  {
    value: "1",
    label: "刀具类",
  },
  {
    value: "2",
    label: "隔套类",
  },
  {
    value: "3",
    label: "辊箱",
  },
  {
    value: "4",
    label: "刀轴",
  },
  {
    value: "5",
    label: "其他",
  },
]);
const clickOrganizationIsdel = () => {
  form.djStatus = djStatus.value;
};
const options = reactive([
  {
    value: "0",
    label: "未审核",
  },

  {
    value: "1",
    label: "已审核",
  },
]);
// const clickOrganizationIsdel = () => {
//   form.djStatus = djStatus.value;
// };
// const options = reactive([
//   {
//     value: "0",
//     label: "未审核",
//   },

//   {
//     value: "1",
//     label: "已审核",
//   },
// ]);
// 修改弹窗
const isDis = ref(false);

const handleRowClick = async (row, selection) => {
  isDis.value = false;
  if (row.state == 1) {
    isDis.value = true;
  }
  dialogTableVisible1.value = true;
  showInsertButton.value = false;
  const res = await newCrud.fetchData("/Part/singleList", "post", {
    info: {
      id: row.id,
      uniqueCode: "",
      modelName: "",
      ecsName: "",
      structureName: "",
      unique_code: "",
      f_type: "",
    },
    pageInfo: {
      page: page.value,
      limit: limit.value,
    },
  });
  console.log(res.info[0]);
  Object.assign(form, res.info[0]);
  form.id = row.id;
  form.model = row.model_id;
  if (form.bus_type == "0") {
    inputTypeTrue.value.true;
  } else {
    inputTypeTrue.value.false;
  }
};
// 新增页面展示
const openInseart = async () => {
  await flushed();
  dialogTableVisible1.value = true;
  showInsertButton.value = true;
  inputTypeTrue.value = true;
  await getUserId();
};

interface RuleForm {
  id: string;
  djNumber: string;
  categoryOfConsumables: string;
  equipmentStructureId: string;
  businessProjectId: string;
  djDate: true;
  djStatus: string;
  partSingleId: string;
  taperStandard: string;
}

//主表字段
const form = reactive<RuleForm>({
  id: "", // 主键ID
  code: "", // 登记单号
  f_date: "", // 登记日期
  unique_code: "", // 单件唯一码
  qr_code: "", //快速检索码
  supplier_unique_code: "", // 供应商唯一码
  material_state: "", // 物料状态
  circulation_state: "", // 流转状态
  material_code: "", // 物料编码
  unit_price: "", // 单价
  quantity: "", // 数量
  amount: "", // 金额
  init_outside_diameter: "", // 外径初始值
  bus_type: "", // 业务类型
  register_num: "", // 登记次数
  special_equipment_id: "", // 专用设备ID
  model_id: "", // 型号ID
  model_name: "", //型号名称
  part_id: "", // 零件ID
  equipment_structure_id: "", // 设备结构ID
  state: "", // 单据状态
  latest_ps_id: "", // 最新磨削工艺标准
  default_ps_id: "", // 默认加工工艺标准
  report_ps_id: "", // 默认统计工艺标准
  remark: "", // 备注
  lock: "", // 锁定状态
  lock_desc: "", // 锁定说明
  lock_info_table: "", // 锁定主表
  lock_info_feild: "", // 锁定主表列名
  lock_info_value: "", // 锁定主表列值
  lock_entity_table: "", // 锁定子表
  lock_entity_feild: "", // 锁定子表列名
  lock_entity_value: "", // 锁定子表列值
  b_lock_info_table: "", // 上一锁定主表
  b_lock_info_feild: "", // 上一锁定主表列名
  b_lock_info_value: "", // 上一锁定主表列值
  b_lock_entity_table: "", // 上一锁定子表
  b_lock_entity_feild: "", // 上一锁定子表列名
  b_lock_entity_value: "", // 上一锁定子表列值
  is_ratify: "", // 是否需要签批
  ratify_state: "", // 签批状态
  ratify_explain: "", // 签批原因
  ratify_person_id: "", // 签批人ID
  ratify_person_name: "", // 签批姓名
  ratify_desc: "", // 签批意见
  create_person_id: "", // 制单人ID
  create_person_name: "", // 制单人名称
  create_datatime: "", // 制单时间
  modify_person_id: "", // 修改人ID
  modify_person_name: "", // 修改人名称
  modify_datetime: "", // 修改时间
  verify_person_id: "", // 审核人ID
  verify_person_name: "", // 审核人名称
  verify_datetime: "", // 审核时间
  c_g_num: "",
  c_g_quantity: "",
  //型号表
  material: "",
  materialName: "", //材质名称
  model: "",
  modelName: "", //型号名称
  processName: "", //标准名称
  ecs_name: "", //零件名称
  category_name: "", //类别名称
  structureName: "", //结构名称
  init_outside_diameter: "", //初始外径
  grindingTotal: "", //磨削总量
});

const ruleFormRef = ref<FormInstance>();
const rules = reactive<FormRules<RuleForm>>({
  // name: [{ message: "请输入班组名称", trigger: "blur"  }],
});
// 子表展示
const cellStyle1 = ({ row, column, rowIndex, columnIndex }) => {
  return { borderColor: "#B9C9C7", padding: "0px", margin: 0 };
};
const showInsertButton = ref(true);
const multipleTableRef = ref();
const handleSelectionChange1 = (val: any[]) => {
  console.log("Selected Rows:", val);
};

const defaultRowData = {
  id: "",
  djNumber: "",
  categoryOfConsumables: "",
  equipmentStructureId: "",
  businessProjectId: "",
  djDate: "",
  djStatus: 0,
  mid: "",
  partSingleId: "",
  closeStatus: "",
  material: "",
  specification: "",
  model: "",
  workingFaceLength: "",
  allowManualScrap: "",
  weight: "",
  length: "",
  width: "",
  height: "",
  diameter: "",
  thicknessStandard: "",
  innerHoleStandard: "",
  hardnessStandard: "",
  c_g_quantity: "",
  ljgrindingNumber: "",
  ljgrindingTimes: "",
  residualGrindingCapacity: "",
  wlbm: "",
  supplierUniqueCode: "",
  workingFaceOuterDiameterStandard: "",
  nonWorkingFaceOuterDiameterStandard: "",
  roughnessStandard: "",
  taperStandard: "",
  taperLength: "",
  taperHeight: "",
};

const tableData1 = ref([
  {
    ...defaultRowData,
  },
  // More data...
]);
const OFFdialogTableVisible = () => {
  dialogTableVisible1.value = false;
  getModel();
  flushed();
};
const flushed = () => {
  Object.keys(form).forEach((key) => {
    form[key] = "";
  });
  form.bus_type = "0";
  form.material_state = "0";
  form.circulation_state = "0";
  form.lock = "0";
};
const addRow = () => {
  tableData1.value.push({ ...defaultRowData });
};
const requestFormTable = computed(() => {
  //   const usefulDataArray = tableData1.value.filter((item) => item.userId !== "");
  //   return {
  //     childList: usefulDataArray,
  //     ID: form.ID,
  //     name: form.name,
  //     businessTypeID: form.businessTypeID,
  //     BusinessTypeName: form.BusinessTypeName,
  //     BusinessTypeCode: form.BusinessTypeCode,
  //     itemType: form.itemType,
  //     businessProjectID: form.businessProjectID,
  //     description: form.description,
  //     status: form.status ? 1 : 0,
  //   };
});

const updateMaterialsFixed = async () => {
  await isRole();
  if (isTrue.value) {
    return;
  }
  const userName = Cookies.get("userName");
  if (!userName) {
    router.push("/");
    return;
  }
  await getUserId();

  if (confirm("确认保存吗？") == false) {
    return;
  }
  const formMainTableDate = form;
  const jsonObj = {
    info: formMainTableDate,
  };
  const res = await newCrud.sendRequest("/Part/insertSingle", "post", jsonObj);
  if (res.code == 200 || res.code == 1) {
    OFFdialogTableVisible();
  }
};
// role
const isTrue = ref(true);
const isRole = () => {
  isTrue.value = true;
  if (!form.unique_code) {
    notifications.showMessage("请输入单件唯一码", "error");
    return;
  }
  if (!form.supplier_unique_code) {
    notifications.showMessage("请输入供应商唯一码", "error");
    return;
  }
  if (!form.model_id) {
    notifications.showMessage("请选择型号", "error");
    return;
  }
  if (!form.init_outside_diameter) {
    notifications.showMessage("请输入初始外径", "error");
    return;
  }
  if (!form.default_ps_id) {
    notifications.showMessage("请输入初始外径", "error");
    return;
  }
  isTrue.value = false;
};
const insertMaterialsFixed = async () => {
  await isRole();
  if (isTrue.value) {
    return;
  }

  const formMainTableDate = form;
  const jsonObj = {
    info: formMainTableDate,
  };

  const res = await newCrud.sendRequest("/Part/insertSingle", "post", jsonObj);
  console.log(res);
  if (res.code == 200 || res.code == 1) {
    OFFdialogTableVisible();
  }
};
const getSelectedData = () => {
  const selectedRows = multipleTableRef.value.getSelectionRows();
};

const deleteSelectedRows = () => {
  const selectedRows = multipleTableRef.value.getSelectionRows();
  selectedRows.forEach((row) => {
    const index = tableData1.value.indexOf(row);
    if (index !== -1) {
      tableData1.value.splice(index, 1);
    }
  });
};

const deleteRow = (row: any) => {
  const index = tableData1.value.indexOf(row);
  if (index !== -1) {
    tableData1.value.splice(index, 1);
  }
};
const headerCellStyle1 = {
  borderColor: "#B9C9C7",
  backgroundColor: "#F2F4FA",
  fontWeight: "bold",
  color: "#1F2129",
  height: "40px",
  margin: 0,
  padding: 0,
};
const tableData3 = ref([]);
const tableData2 = ref([]);
var indexK3bm = 0;
const getK3vm = () => {
  axios({
    url: "/get/K3bm",
    method: "post",
    data: {
      page: page2.value,
      limit: limit2.value,
      k3bm: inputK3Bm.value,
      k3mc: inputK3Mc.value,
    },
  }).then((res) => {
    tableData3.value = res.data;
    if (res.data.length == 0) {
      total3.value == 0;
      return;
    }
    total3.value = res.data[0].total;
  });
};
const inputK3Bm = ref("");
const inputK3Mc = ref("");
const openWlbm = () => {
  dialogTableVisible4.value = true;
  getK3vm();
};
const handleSizeChange3 = (val: number) => {
  axios({
    url: "/get/K3bm",
    method: "post",
    data: {
      page: page2.value,
      limit: limit2.value,
      k3bm: inputK3Bm.value,
      k3mc: inputK3Mc.value,
    },
  }).then((res) => {
    tableData3.value = res.data;
    if (res.data.length == 0) {
      total3.value == 0;
      return;
    }
    total3.value = res.data[0].total;
  });
};
const handleCurrentChange3 = (val: number) => {
  axios({
    url: "/get/K3bm",
    method: "post",
    data: {
      page: page2.value,
      limit: limit2.value,
      k3bm: inputK3Bm.value,
      k3mc: inputK3Mc.value,
    },
  }).then((res) => {
    tableData3.value = res.data;
    if (res.data.length == 0) {
      total3.value == 0;
      return;
    }
    total3.value = res.data[0].total;
  });
};
const searc3Kh = () => {
  axios({
    url: "/get/K3bm",
    method: "post",
    data: {
      page: page2.value,
      limit: limit2.value,
      k3bm: inputK3Bm.value,
      k3mc: inputK3Mc.value,
    },
  }).then((res) => {
    tableData3.value = res.data;
    if (res.data.length == 0) {
      total3.value == 0;
      return;
    }
    total3.value = res.data[0].total;
  });
};

const updateK3 = () => {
  ElMessageBox.confirm("确认更新吗？", "提示", {
    confirmButtonText: "确认",
    cancelButtonText: "取消",
    type: "warning",
    center: true,
  })
    .then(() => {
      axios({
        url: "/update/Jd/K3bm",
        method: "post",
        data: {},
      }).then((res) => {
        if (res.data.code == 200) {
          ElMessage({
            center: true,
            showClose: true,
            grouping: true,
            offset: window.screen.height / 9,
            message: res.data.message,
            type: "success",
          });
          searc3Kh();
          return;
        }
        ElMessage({
          center: true,
          showClose: true,
          grouping: true,
          offset: window.screen.height / 9,
          message: res.data.message,
          type: "error",
        });
      });
    })
    .catch(() => {});
};
const openBusiness = (index) => {
  dialogTableVisible2.value = true;
  geSysStatus();
};
const handleSizeChange2 = (val: number) => {
  geSysStatus();
};
const handleCurrentChange2 = (val: number) => {
  geSysStatus();
};
const selectedRows2 = ref([]);
const handleSelectionChange2 = (val) => {
  selectedRows2.value = val;
};
const geSysStatus = () => {
  axios({
    url: "/Part/select/EquipmentMechanicalStructureMapping",
    method: "post",
    data: {
      ID: ID.value,
      page: page2.value,
      limit: limit2.value,
    },
  }).then((res) => {
    const statusList = res.data;
    tableData2.value = [];
    if (statusList.length == 0) {
      total2.value = 0;
      return;
    }
    total2.value = statusList[0].total;
    console.log(res.data);
    tableData2.value = statusList.map((test) => ({
      // 根据 djzt 的值设置状态
      // zt: test.zt === 0 ? "待审" : "已审核",
      autoId: test.autoId,
      ID: test.id,
      equipmentId: test.equipmentId,
      mechanicalStructureId: test.mechanicalStructureId,
      structureID: test.structureID,
      equipmentName: test.equipmentName,
      structureName: test.structureName,
      quantity: test.quantity,
      model: test.model,
      model_id: test.model,
      status: test.status,
      cid: test.cid,
      workingFaceOuterDiameterStandard: test.workingFaceOuterDiameterStandard,
      minWorkingFaceOuterDiameter: test.minWorkingFaceOuterDiameter,
      maxWorkingFaceOuterDiameter: test.maxWorkingFaceOuterDiameter,
      ecs_name: test.componentName,
      category_name: test.categoryName,
    }));
  });
};
const RowClick2 = (row, selection) => {
  console.log(row);
  form.modelName = row.model;
  form.model_name = row.model;
  form.model = row.cid;
  form.model_id = row.cid;
  form.workingFaceOuterDiameterStandard = row.workingFaceOuterDiameterStandard;
  form.minWorkingFaceOuterDiameter = row.minWorkingFaceOuterDiameter;
  form.maxWorkingFaceOuterDiameter = row.maxWorkingFaceOuterDiameter;
  form.structureName = row.structureName;
  form.ecs_name = row.ecs_name;
  form.category_name = row.category_name;
  dialogTableVisible2.value = false;
};
const RowClick3 = (row) => {
  form.wlbm = row.fnumber;
  dialogTableVisible4.value = false;
};
// 弹窗
const indexEmployeeJob = ref(0);

const flushed1 = () => {
  form.value = [];
  for (let a = 0; a < 21; a++) {
    addRow();
  }
};
const inputTypeTrue = ref(true);
const inputTypeChange = () => {
  if (form.bus_type == "0") {
    form.material_state = "0";
    form.circulation_state = "0";
    form.lock = "0";
    inputTypeTrue.value = true;
  } else {
    inputTypeTrue.value = false;
  }
};
//页面改动
//零部件单件登记表new
const InitDiameterBlur = (prop, rowIndex) => {
  const val = form[prop];
  if (!isNaN(parseFloat(val)) && isFinite(val)) {
    // 将数字保留四位小数
    //  form[prop] = parseFloat(val).toFixed(4);
    const roundedVal = parseFloat(val)
      .toString()
      .match(/^-?\d+(\.\d{0,4})?/)[0];
    form[prop] = roundedVal;
    form.residualGrindingCapacity = roundedVal - form.minWorkingFaceOuterDiameter;
  } else {
    // 如果不是有效数字，清空表单
    form[prop] = "";
  }
};
//默认标准
const sed = ref<any>(null);
const openEqipmentParts = async () => {
  if (!form.model_id) {
    notifications.showMessage("请先选择型号", "error");
    return;
  }
  sed.value.dialogTableVisible = true;
  openDial();
};
const tableDemo = ref([
  { type: "index", fixed: true, width: "60", align: "center" },
  //   { type: "selection", width: "65", align: "center" },
  { prop: "processCode", label: "工艺编号", width: "120", align: "center" },
  { prop: "processName", label: "工艺名称", width: "350", align: "center" },
  { prop: "explain", label: "说明", width: "200", align: "center" },
  { prop: "passToolNumber", label: "道次", width: "120", align: "center" },
]);
const openDial = () => {
  sed.value.ifRowChoose = false;
  sed.value.input1 = form.model;
  sed.value.tableColumns = tableDemo.value;
  sed.value.compareValue = "id";
  sed.value.apiUrl = "/Gri/update/selectGmModel";
  sed.value.searchInput();
};
const handleRowData = async (row) => {
  console.log(row);
  form.default_ps_id = row.id;
  form.latest_ps_id = row.id;
  form.report_ps_id = row.id;
  form.processName = row.processName;
  //   form.grindingTotal
};
</script>
<style scoped>
.el-table {
  /* --el-table-row-hover-bg-color: rgba(0, 158, 250, 0.219) !important; */
  /* --el-table-row-hover-bg-color: #fef5f0 !important; */
  --el-table-row-hover-bg-color: rgba(254, 245, 240, 0.8) !important;
}

/* 选中 */
.el-table {
  /* --el-table-row-hover-bg-color: #fef5f0 !important; */
  --el-table-row-hover-bg-color: rgba(254, 245, 240, 0.8) !important;
}

.down-tree ::v-deep .el-tree-node.is-expanded > .el-tree-node__children {
  display: inline;
}

.down-tree {
  height: 100%;
}

.demo-pagination-block {
  float: right;
}

.custom-dialog {
  position: fixed;
  top: 10em;
  left: 50%;
  width: 20%;
  /* 其他样式... */
}

.demo-form-inline .el-input {
  --el-input-width: 220px;
}

.labs {
  margin-bottom: 0px;
}

.lab {
  background-color: rgba(247, 247, 247, 0.903);
  /* border-radius: 5px; */
  text-align: center;
  margin-bottom: 0px;
  text-align: right;
}
</style>
